package com.example.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.shop.entity.Cart;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface CartMapper extends BaseMapper<Cart> {
    @Update("update shop_carts set quantity=quantity+1 where member_id=#{memberId} and goods_id=#{goodsId}")
    int updateCart(int memberId, int goodsId, int quantity);

    @Select("select sum(pay_price*quantity) as total_amount from shop_carts where member_id=#{memberId} and selected=1")
    double getCartTotalAmount(int memberId);

    @Update("update shop_carts set selected=#{selected} where id=#{id}")
    int updateSelectedById(Long id, int selected);

    @Update("update shop_carts set selected=#{selected} where id in ${ids}")
    int batchUpdateSelected(@Param("ids") String ids, int selected);

    @Update("update shop_carts set quantity=#{quantity} where id=#{id}")
    int updateCartQuantity(int id, int quantity);
}
